import {reqCategoryList,reqBannerList,reqFloorList} from '@/api'

// home模块的小仓库
const state = {
    // 初始值，格式取决于服务器返回的数据
    categoryList: [],
    bannerList: [],
    floorList: []
}
// 唯一修改state的地方
const mutations = {
    CATEFORYLIST(state,categoryList){
        state.categoryList = categoryList
    },
    GETCATEGORY(state,bannerList){
        state.bannerList = bannerList
    },
    GETFLOORLIST(state,floorList){
        state.floorList = floorList
    }

}
// 派发action的地方
const actions = {
     async categoryList({commit}){
        let res = await reqCategoryList()
        // console.log(res);
        if(res.data.code === 200){
            commit('CATEFORYLIST',res.data.data)
        }
    },
    // 获取轮播图数据
    async getBannerList({commit}){
        let res = await reqBannerList()
        if(res.data.code === 200){
            commit('GETCATEGORY',res.data.data)
        }
        // console.log(res);
    },
    // 获取floor数据
    async getFloorList({commit}){
        let res = await reqFloorList()
        if(res.data.code === 200){
            // 提交mutation
            commit('GETFLOORLIST',res.data.data)
        }
    }
}

const getters = {}
export default {
     state,
     mutations,
     actions,
     getters
}